#include "CTableManager.h"

void CTableManager::AddTable(const std::string& tableName, CTableBasePtr table)
{
	if (table && !tableName.empty())
	{
		m_tableMap[tableName] = table;
	}
}
CTableBasePtr CTableManager::GetTable(const std::string& tableName) const
{
	auto it = m_tableMap.find(tableName);
	if (it != m_tableMap.end())
	{
		return it->second;
	}
	return nullptr;
}
bool CTableManager::HasTable(const std::string& tableName) const
{
	return m_tableMap.find(tableName) != m_tableMap.end();
}
void CTableManager::RemoveTable(const std::string& tableName)
{
	auto it = m_tableMap.find(tableName);
	if (it != m_tableMap.end())
	{
		m_tableMap.erase(it);
	}
}

int CTableManager::InitAllTables()
{
	for (auto& pair : m_tableMap)
	{
		CTableBasePtr table = pair.second;
		if (table)
		{
			int ret = table->InitTable();
			if (ret != 0)
			{
				return ret; // Return error code if initialization fails
			}
		}
	}
	return 0; // All tables initialized successfully
}

CTableManager::~CTableManager()
{
	// Clear the table map
	m_tableMap.clear();
}
